package com.sso.gateway.domain.security.impl;

import com.sso.gateway.domain.security.WhiteListDomainService;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class SimpleWhiteListDomainService implements WhiteListDomainService {

    private static final List<String> WHITE_LIST = Arrays.asList(
            "/auth/login",
            "/auth/register",
            "/auth/captcha",
            "/actuator/**"
    );

    @Override
    public boolean isWhitePath(String path) {
        return WHITE_LIST.stream().anyMatch(whitePath -> {
            if (whitePath.endsWith("/**")) {
                String prefix = whitePath.substring(0, whitePath.length() - 2);
                return path.startsWith(prefix);
            }
            return path.equals(whitePath);
        });
    }
}
